package org.windey.applet;

public class StreamThread extends Thread
{
	private WindeyServerConnection connection;
	private WindeyApplet applet;
	
	public StreamThread(WindeyServerConnection connection, WindeyApplet applet)
	{
		this.connection = connection;
		this.applet = applet;
	}
	
	public void run()
	{
        
		while (connection.isConnected())
		{
			try {
				String[] line = connection.receive().split(":");
				String[] data = line[1].split(",");
				int lineNumber = Integer.parseInt(line[0]);
				for (int x = 0; x < data.length; x++)
				{
					applet.setPixel(x, lineNumber, Integer.parseInt(data[x]));
					applet.repaint() ;
				}
			}
			catch (IndexOutOfBoundsException e) {
				
			}
			catch (NumberFormatException e) {
				// TODO: handle exception
			}
		}
	}
}
